// ai 配置文件
class AIBaseConfig {
  String? appName;
  String? appIconUrl;
  String? title;
  String? desc;
  bool? o2AiEnable;

  AIBaseConfig(
      {this.appName, this.appIconUrl, this.title, this.desc, this.o2AiEnable});

  factory AIBaseConfig.fromJson(Map<String, dynamic> json) {
    return AIBaseConfig(
      appName: json['appName'],
      appIconUrl: json['appIconUrl'],
      title: json['title'],
      desc: json['desc'],
      o2AiEnable: json['o2AiEnable'],
    );
  }
  Map<String, dynamic> toJson() {
    return {
      'appName': appName,
      'appIconUrl': appIconUrl,
      'title': title,
      'desc': desc,
      'o2AiEnable': o2AiEnable,
    };
  }
}

// ai 会话
class AIClueInfo {
  String? id;
  String? person;
  String? title;
  String? createDateTime;
  String? updateDateTime;

  String? groupTag; // 分组显示用
  int? groupOrder; // 分组排序

  AIClueInfo(
      {this.id,
      this.person,
      this.title,
      this.createDateTime,
      this.updateDateTime,
      this.groupOrder,
      this.groupTag});

  factory AIClueInfo.fromJson(Map<String, dynamic> json) {
    return AIClueInfo(
      id: json['id'],
      person: json['person'],
      title: json['title'],
      createDateTime: json['createDateTime'],
      updateDateTime: json['updateDateTime'],
      groupTag: json['groupTag'],
      groupOrder: json['groupOrder'],
    );
  }
  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'person': person,
      'title': title,
      'createDateTime': createDateTime,
      'updateDateTime': updateDateTime,
      'groupTag': groupTag,
      'groupOrder': groupOrder,
    };
  }

}

// ai 模式对象 聊天｜知识库｜MCP 等
class AIGenerateTypeInfo {
  String? iconClass;
  String? key;
  String? name;
  String? desc;

  AIGenerateTypeInfo({this.iconClass, this.key, this.name, this.desc});
  factory AIGenerateTypeInfo.fromJson(Map<String, dynamic> json) {
    return AIGenerateTypeInfo(
      iconClass: json['iconClass'],
      key: json['key'],
      name: json['name'],
      desc: json['desc'],
    );
  }
  Map<String, dynamic> toJson() {
    return {
      'iconClass': iconClass,
      'key': key,
      'name': name,
      'desc': desc,
    };
  }
}

// ai 对话消息对象
class AIChatInfo {
  String? id;
  String? person;
  String? clueId;
  String? generateType;
  String? input;
  String? content;
  List<String>? materialIdList;
  String? createDateTime;
  String? updateDateTime;
  Map<String, dynamic>? extra;

  AIChatInfo(
      {this.id,
      this.person,
      this.clueId,
      this.generateType,
      this.input,
      this.content,
      this.materialIdList,
      this.createDateTime,
      this.updateDateTime, this.extra});
  factory AIChatInfo.fromJson(Map<String, dynamic> json) {
    return AIChatInfo(
      id: json['id'],
      person: json['person'],
      clueId: json['clueId'],
      generateType: json['generateType'],
      input: json['input'],
      content: json['content'],
      materialIdList: json['materialIdList'] == null
          ? null
          : List<String>.from(json['materialIdList'].map((x) => x)),
      createDateTime: json['createDateTime'],
      updateDateTime: json['updateDateTime'],
      extra: json['extra'],
    );
  }
  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'person': person,
      'clueId': clueId,
      'generateType': generateType,
      'input': input,
      'content': content,
      'materialIdList': materialIdList,
      'createDateTime': createDateTime,
      'updateDateTime': updateDateTime,
      'extra': extra,
    };
  }
}

class AIChatAttachmentInfo {
  String? id;
  String? name;
  String? creator;
  String? referenceId;
  String? fileId;
  String? status;
  String? extension;
  int? length;
  String? createTime;
  String? updateTime;

  AIChatAttachmentInfo(
      {this.id,
      this.name,
      this.creator,
      this.referenceId,
      this.fileId,
      this.status,
      this.extension,
      this.length,
      this.createTime,
      this.updateTime});
  factory AIChatAttachmentInfo.fromJson(Map<String, dynamic> json) {
    return AIChatAttachmentInfo(
      id: json['id'],
      name: json['name'],
      creator: json['creator'],
      referenceId: json['referenceId'],
      fileId: json['fileId'],
      status: json['status'],
      extension: json['extension'],
      length: json['length'],
      createTime: json['createTime'],
      updateTime: json['updateTime'],
    );
  }
  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'name': name,
      'creator': creator,
      'referenceId': referenceId,
      'fileId': fileId,
      'status': status,
      'extension': extension,
      'length': length,
      'createTime': createTime,
      'updateTime': updateTime,
    };
  }
}

// ai 对话发送对象
class AIChatPost {
  String? input; // 输入内容
  String? clueId; // 线索id
  String? generateType; //ai模式：chat|rag|mcp
  List<String>? materialIdList; // 附件id

  AIChatPost({this.input, this.clueId, this.generateType, this.materialIdList});
  factory AIChatPost.fromJson(Map<String, dynamic> json) {
    return AIChatPost(
      input: json['input'],
      clueId: json['clueId'],
      generateType: json['generateType'],
      materialIdList: json['materialIdList'] == null
          ? null
          : List<String>.from(json['materialIdList'].map((x) => x)),
    );
  }
  Map<String, dynamic> toJson() {
    return {
      'input': input,
      'clueId': clueId,
      'generateType': generateType,
      'materialIdList': materialIdList,
    };
  }
}

// ai 模型返回数据对象
class AIChatContent {
  String? id;
  String? object;
  int? created;
  String? model;
  String? system_fingerprint;
  List<AIChatContentChoice>? choices;

  AIChatContent(
      {this.id,
      this.object,
      this.created,
      this.model,
      this.system_fingerprint,
      this.choices});
  factory AIChatContent.fromJson(Map<String, dynamic> json) {
    return AIChatContent(
      id: json['id'],
      object: json['object'],
      created: json['created'],
      model: json['model'],
      system_fingerprint: json['system_fingerprint'],
      choices: json['choices'] == null
          ? null
          : List<AIChatContentChoice>.from(
              json['choices'].map((x) => AIChatContentChoice.fromJson(x))),
    );
  }
  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'object': object,
      'created': created,
      'model': model,
      'system_fingerprint': system_fingerprint,
      'choices': choices?.map((x) => x.toJson()),
    };
  }
}

class AIChatContentChoice {
  int? index;
  AIChatContentChoiceDelta? delta;
  AIChatContentChoiceMessage? message;
  String? finish_reason;

  AIChatContentChoice(
      {this.index, this.delta, this.finish_reason, this.message});
  factory AIChatContentChoice.fromJson(Map<String, dynamic> json) {
    return AIChatContentChoice(
        index: json['index'],
        delta: json['delta'] == null
            ? null
            : AIChatContentChoiceDelta.fromJson(json['delta']),
        message: json['message'] == null
            ? null
            : AIChatContentChoiceMessage.fromJson(json['message']),
        finish_reason: json['finish_reason']);
  }
  Map<String, dynamic> toJson() {
    return {
      'index': index,
      'delta': delta?.toJson(),
      'message': message?.toJson(),
      'finish_reason': finish_reason,
    };
  }
}

class AIChatContentChoiceMessage {
  String? content;
  String? role;

  AIChatContentChoiceMessage({this.content, this.role});
  factory AIChatContentChoiceMessage.fromJson(Map<String, dynamic> json) {
    return AIChatContentChoiceMessage(
      content: json['content'],
      role: json['role'],
    );
  }
  Map<String, dynamic> toJson() {
    return {
      'content': content,
      'role': role,
    };
  }
}

class AIChatContentChoiceDelta {
  String? content;

  AIChatContentChoiceDelta({this.content});
  factory AIChatContentChoiceDelta.fromJson(Map<String, dynamic> json) {
    return AIChatContentChoiceDelta(
      content: json['content'],
    );
  }
  Map<String, dynamic> toJson() {
    return {
      'content': content,
    };
  }
}

// 上传附件对象
class AIFileUploadItem {
  String? fileId; // 上传后的id
  String? fileLocalPath; // 没有上次的本地地址
  String? ext; // 文件扩展名

  AIFileUploadItem({this.fileId, this.fileLocalPath, this.ext});

  factory AIFileUploadItem.fromJson(Map<String, dynamic> json) {
    return AIFileUploadItem(
      fileId: json['fileId'],
      fileLocalPath: json['fileLocalPath'],
      ext: json['ext'],
    );
  }
  Map<String, dynamic> toJson() => {
        "fileId": fileId,
        "fileLocalPath": fileLocalPath,
        "ext": ext,
      };
}

/// MCP 的时候返回的结果
class AIMCPResultInfo {
  String? type;
  String? name;
  String? mctFlag;
  dynamic data;

  AIMCPResultInfo({this.type, this.name, this.mctFlag, this.data});
  factory AIMCPResultInfo.fromJson(Map<String, dynamic> json) {
    return AIMCPResultInfo(
      type: json['type'],
      name: json['name'],
      mctFlag: json['mctFlag'],
      data: json['data'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'type': type,
      'name': name,
      'mctFlag': mctFlag,
      'data': data,
    };
  }
}

class KeyValueViewInfo {
  String key;
  String value;
  KeyValueViewInfo({required this.key, required this.value});

  factory KeyValueViewInfo.fromJson(Map<String, dynamic> json) {
    return KeyValueViewInfo(
      key: json['key'] ?? '',
      value: json['value'] ?? '',
    );
  }
}

class AICardViewInfo {
  String? title;
  List<KeyValueViewInfo>? attributeList;
  String? moreBtnTitle;

  AICardViewInfo({this.title, this.attributeList, this.moreBtnTitle});

  factory AICardViewInfo.fromJson(Map<String, dynamic> json) {
    return AICardViewInfo(
      title: json['title'],
      attributeList: json['attributeList'] == null
          ? null
          : List<KeyValueViewInfo>.from(
              json['attributeList'].map((x) => KeyValueViewInfo.fromJson(x))),
      moreBtnTitle: json['moreBtnTitle'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'title': title,
      'attributeList': attributeList,
      'moreBtnTitle': moreBtnTitle,
    };
  }
}

// 加班申请 流程 AI MCP 返回结果
class AIProcessOvertimeResponse {
  String? title;
  String? identity;
  String? work;
  dynamic data;

  AIProcessOvertimeResponse({
    this.title,
    this.identity,
    this.work,
    this.data
  });

   factory AIProcessOvertimeResponse.fromJson(Map<String, dynamic> json) {
    return AIProcessOvertimeResponse(
      title: json['title'],
      identity: json['identity'] ,
      work: json['work'],
      data: json['data'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'title': title,
      'identity': identity,
      'work': work,
      'data': data,
    };
  }

}
 